﻿using Ndns.Packet.Abstractions;
using System.Collections.Generic;

namespace Ndns.ServerHost.Abstractions
{
    public class DnsQueryAnswers
    {
        /// <summary>
        /// 表明服务器是域的权威
        /// </summary>
        public bool ServerAuthoritative { get; set; }

        /// <summary>
        /// 表示服务器可以进行递归查询
        /// </summary>
        public bool RecursionAvailable { get; set; }

        /// <summary>
        /// 表示应答已经经过权威认证
        /// </summary>
        public bool AnswerAuthenticated { get; set; }

        /// <summary>
        /// 应答集合
        /// </summary>
        public IList<DnsResourceRecord> AnswerRRs { get; }

        /// <summary>
        /// 权威应答集合
        /// </summary>
        public IList<DnsResourceRecord> AuthoritativeNSs { get; }

        /// <summary>
        /// 额外应答集合
        /// </summary>
        public IList<DnsResourceRecord> AdditionalRRs { get; }

        public DnsQueryAnswers()
        {
            AnswerRRs = new List<DnsResourceRecord>();
            AuthoritativeNSs = new List<DnsResourceRecord>();
            AdditionalRRs = new List<DnsResourceRecord>();
        }

        private DnsQueryAnswers(IList<DnsResourceRecord> answerRRs, IList<DnsResourceRecord> authoritativeNSs, IList<DnsResourceRecord> additionalRRs)
        {
            AnswerRRs = new List<DnsResourceRecord>(answerRRs);
            AuthoritativeNSs = new List<DnsResourceRecord>(authoritativeNSs);
            AdditionalRRs = new List<DnsResourceRecord>(additionalRRs);
        }
        public DnsQueryAnswers Clone()
        {
            var answers = new DnsQueryAnswers(AnswerRRs, AuthoritativeNSs, AdditionalRRs);
            answers.ServerAuthoritative = ServerAuthoritative;
            answers.RecursionAvailable = RecursionAvailable;
            answers.AnswerAuthenticated = AnswerAuthenticated;
            return answers;
        }

        public int Count => AnswerRRs.Count + AuthoritativeNSs.Count + AdditionalRRs.Count;
    }
}
